// pages/receiptAdd/receiptAdd.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    mid:0,
    user:{},
    line:{},
    spole:{},
    epole:{},
    main:{},
    uid:0,
    pole:[],
    intactRate:0,
    description:'',
    date:'2000-01-01',
    pindex:0,
    bugType:['叉梁断裂','拦河线断裂','绝缘子爆破','杆塔倾斜','横杠弯曲下垂','瓷瓶破裂','吊杆变形','其他',],
    typeIndex:0,
    bugLv:['一般','紧急','严重'],
    lvIndex:0
  },
  poleChange: function (e) {
    console.log(e)
    this.setData({
      pindex: e.detail.value
    })
  },
  intact(e){
    //console.log(e)
    this.setData({
      intactRate:e.detail.detail.value
    })
  },
  descr(e){
    this.setData({
      description:e.detail.detail.value
    })
  },
  lvChange: function (e) {
    console.log(e)
    this.setData({
      lvIndex: e.detail.value
    })
  },
  typeChange: function (e) {
    console.log(e)
    this.setData({
      typeIndex: e.detail.value
    })
  },
  bindDateChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value
    })
  },
  add(){
    wx.request({
      url: 'http://127.0.0.1:8080/receiptAdd',
      data:{
        taskid:this.data.main.id,
        poleid:this.data.pindex==0?this.data.spole.id:this.data.epole.id,
        intactRate:this.data.intactRate,
        bugLevelId:this.data.lvIndex,
        bugTypeId:this.data.typeIndex,
        bugdesc:this.data.description,
        uid:this.data.user.id,
        distime:this.data.date
      },
      success:res=>{
        //console.log(res)
        if(res.data){
          wx.showToast({
            title: '添加完成',
          })
          setTimeout(() => {
            wx.navigateBack({
              complete: (res) => {},
            })
          }, 1500);
        }else{
          wx.showToast({
            title: '添加失败',
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    this.setData({
      mid:options.mid,
      uid:options.uid
    })
    wx.request({
      url: 'http://127.0.0.1:8080/subi?id=1'+this.data.uid,
      success:ues=>{
        this.setData({
          user:ues.data
        })
      }
    })
    wx.request({
      url: 'http://127.0.0.1:8080/selectInspectionByid?id='+this.data.mid,
      success:res=>{
        this.setData({
          main:res.data
        })
        setTimeout(() => {
          wx.request({
            url: 'http://127.0.0.1:8080/selectPsLineInfoById?id='+this.data.main.lineid,
            success:les=>{
              //console.log(les)
              this.setData({
                line:les.data
              })
            }
          })

          wx.request({
            url: 'http://127.0.0.1:8080/selectPoleById?id='+this.data.main.startpole,
            success:spes=>{
              this.setData({
                spole:spes.data,
                pole:this.data.pole.concat(spes.data.polecode)
              })
            }
          })
          setTimeout(() => {
            wx.request({
              url: 'http://127.0.0.1:8080/selectPoleById?id='+this.data.main.endpole,
              success:epes=>{
                this.setData({
                  epole:epes.data,
                  pole:this.data.pole.concat(epes.data.polecode)
                })
              }
            })
          }, 100);

        }, 200);

      }
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})